#ifndef YCCOREUTILS_H
#define YCCOREUTILS_H
#include <QList>
#include <QObject>

namespace yc {
namespace coreutils {

// 派生类列表转为基类列表
template<class D, class B>
QList<B> baseListCast(const QList<D>& ds)
{
    QList<B> bs;
    for (D p : ds) {
        bs.push_back(p);
    }
    return bs;
}

template<class B, class D>
QList<D> derivedListCast(const QList<B>& bs)
{
    QList<D> ds;
    for (B p : bs) {
        if (D d = qobject_cast<D>(p)) {
            ds.push_back(d);
        }
    }
    return ds;
}

template<class B, class D>
QList<D> derivedListCast(const QList<B>& bs, int type)
{
    QList<D> ds;
    for (B p : bs) {
        if (p->type() == type) {
            if (D d = qobject_cast<D>(p)) {
                ds.push_back(d);
            }
        }
    }
    return ds;
}

template<class T>
bool areSameType(const QList<T>& ls, int type)
{
    bool same = false;
    if (!ls.empty()) {
        same = true;
        for (T p : ls) {
            if (type != p->type()) {
                same = false;
                break;
            }
        }
    }
    return same;
}

// 支持的图片/音频/视频格式
QString supportImageFormats();
QString supportAudioFormats();
QString supportVideoFormats();

} // namespace utils
} // namespace yc

#endif // YCCOREUTILS_H
